package com.ruoyi.project.countrybus.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.countrybus.domain.SysStation;
import com.ruoyi.project.countrybus.service.ISysStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 站点信息Controller
 * 
 * @author yangwenbo
 * @date 2022-04-05
 */
@RestController
@RequestMapping("/countrybus/station")
public class SysStationController extends BaseController
{
    @Autowired
    private ISysStationService sysStationService;

    /**
     * 查询站点信息列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStation sysStation)
    {
        startPage();
        List<SysStation> list = sysStationService.selectSysStationList(sysStation);
        return getDataTable(list);
    }

    /**
     * 导出站点信息列表
     */
    @PreAuthorize("@ss.hasPermi('countrybus:station:export')")
    @Log(title = "站点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStation sysStation)
    {
        List<SysStation> list = sysStationService.selectSysStationList(sysStation);
        ExcelUtil<SysStation> util = new ExcelUtil<SysStation>(SysStation.class);
        util.exportExcel(response, list, "站点信息数据");
    }

    /**
     * 获取站点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:station:query')")
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Long stationId)
    {
        return AjaxResult.success(sysStationService.selectSysStationByStationId(stationId));
    }

    /**
     * 新增站点信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:station:add')")
    @Log(title = "站点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStation sysStation)
    {
        return toAjax(sysStationService.insertSysStation(sysStation));
    }

    /**
     * 修改站点信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:station:edit')")
    @Log(title = "站点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStation sysStation)
    {
        return toAjax(sysStationService.updateSysStation(sysStation));
    }

    /**
     * 删除站点信息
     */
    @PreAuthorize("@ss.hasPermi('countrybus:station:remove')")
    @Log(title = "站点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable Long[] stationIds)
    {
        return toAjax(sysStationService.deleteSysStationByStationIds(stationIds));
    }
}
